$(document).ready(function () {
    optionini();
    initPagination();
});

//条件查询开始
$("#distpicker1").distpicker({
    autoSelect: false
});

//条件查询结束
//表格头部字段筛选
var initiator_select;//发起方
var proName_select='';//发起场景
var isEffective_select='';//通话有效性
var isGoodCall_select;//通话质量
var callStatus_select='null#null';//通话结果
var callDurationMin;//通话最短周期
var calledDuration_V;
var sceneSelector = $('#proName_select');
var json = {};
function optionini(){
    $.ajax(
        {
            type: "post",
            url: "/product/option",
            data: json,
            dataType: "json",
            success: function (data) {
                var result = data.data.result;
                sceneSelector.html();
                for (x in  result) {
                    sceneSelector.append('<option value="' + result[x].proid + '">' + result[x].proName + '</option>');
                }
            }, error: function () {
            alert("报错了");
        }

        }
    );
}


var orderBy="";
var datas = [
    {
        name: '客户姓名',
        className: '.client-name',
        parameter: ''
    },
    {
        name: '客户电话',
        className: '.client-phone',
        parameter: ''
    },
    {
        name: '律师姓名',
        className: '.lawyer-name',
        parameter: ''
    },
    {
        name: '律师电话',
        className: '.lawyer-phone',
        parameter: ''
    },
    {
        name: '发起时刻start',
        className: '#start-time',
        parameter: ''
    },
    {
        name: '发起时刻end',
        className: '#end-time',
        parameter: ''
    },
    {
        name: '通话时长start',
        className: '.start-num',
        parameter: ''
    },
    {
        name: '通话时长end',
        className: '.end-num',
        parameter: ''
    }
]

$('.seek-btn').on('click',function(){
    initPagination();
});



//清空条件
$('.seek-clear').on('click', function () {
    for (var i = 0; i < datas.length; i++) {
        var data = datas[i];
        $(data.className).val('');
    }
})



$(".form-control").on("change",
    function () {
        var v = $(this).val();
        var cn = $(this)["0"].attributes[1].nodeValue;
        if (cn == 'initiator_select') {
            initiator_select = v;
        } else if (cn == 'proName_select') {
            proName_select = v;
        } else if (cn == 'isEffective_select') {
            isEffective_select = v;
        } else if (cn == 'isGoodCall_select') {
            isGoodCall_select = v;
        } else if (cn == 'callStatus_select') {
            callStatus_select = v;
        } else {

        }
        initPagination();
    }
);
//通话质量筛选
$("#quality").on("click",
    function () {
        isGoodCall_select = $(this)["0"].checked;
        if (isGoodCall_select == true) {
            isGoodCall_select = 'good';
        } else {
            isGoodCall_select = '';
        }
        initPagination();
    }
);
//表格头部升序 降序
$('.sequence').on('click', function () {
    var pxzd = $(this).attr("pxzd");
    if ($(this).hasClass('isup')) {
        $(this).removeClass('isup').addClass('isdown');
        //  创建时间 降序排序
        if (pxzd == 'create-time') {
            orderBy = 0;
        }
        else {
            orderBy = 1;
        }
    } else if ($(this).hasClass('isdown')) {
        $(this).removeClass('isdown').addClass('isup');
        //时间升序排序
        if (pxzd == 'create-time') {
            orderBy = 2;
        }
        else {
            orderBy = 3;
        }
    } else {
        $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');
        $(this).addClass('isup');
        //ajax传递
        if (pxzd == 'create-time') {
            orderBy = 1;
        }
        else {
            orderBy = 3;
        }
    }
    initPagination();
})
//分页
function initPagination() {
    // 创建分页
    //获取总行数
    var totalcount = getCount();
    //按照下标进行查询
    $("#Pagination").pagination(totalcount, {
        num_edge_entries: 0, //边缘页数
        num_display_entries: 10, //主体页数
        callback: pageselectCallback, //回调函数
        items_per_page: 10, //每页显示10项
        prev_text: "上一页",
        next_text: "下一页",
        ellipse_text: "...",//省略的文本
        prev_show_always: true,//是否总显示“前一页”分页按钮
        next_show_always: true,//是否总显示“下一页”分页按钮，
    });
    $("#currentCount").text("咨询数量："+totalcount);
};
function pageselectCallback(page_index, jq) {
    query(page_index, jq);
}
//   表格部分结束
function query(page_index, jq) {
    //发送ajax;
    $.ajax(
        {
            type: "post",
            url: "/call/recordList",
            data: getJson(page_index, jq),
            dataType: "json",
            async: false,
            success: function (data) {
                var result = data.data;
                var tmpl1 = bt('list1', result);
                $("#tbody1").html(tmpl1);


            }, error: function () {
            alert("报错了");
        }
        }
    );
}
<!--录音弹框-->
function audioClick(obj){
    var tr = $(obj).parents("tr");
    var voiceUrl_v = tr.find('.voiceUrl').text();
    tr.find("td").each(function () {
        var key_kp = $(this)["0"].className + "_kp";
        if ($('#' + key_kp)) {
            if (key_kp == 'voiceUrl_kp') {
                $('#' + key_kp).attr('src', voiceUrl_v);
            } else {
                $('#' + key_kp).html($(this).text());
            }
        }
    });
    $("#audio-detail").cmsmodal('show');
}

function getJson(page_index, jq) {
    var queryjson;
    //验证手机号格式
    var clientphone = $('.client-phone').val() && $('.client-phone').val().trim();
    if (clientphone && !(/^1[34578]\d{9}$/.test(clientphone))) {
        alert('请输入正确的客户电话');
        return;
    }
    var lawyerphone = $('.lawyer-phone').val() && $('.lawyer-phone').val().trim();
    if (lawyerphone && !(/^1[34578]\d{9}$/.test(lawyerphone))) {
        alert('请输入正确的律师电话');
        return;
    }
    queryjson = {
        uname: $('.client-name')["0"].value,
        uphone: $('.client-phone')["0"].value,
        lawyername: $('.lawyer-name')["0"].value,
        lawyerPhone: $('.lawyer-phone')["0"].value,
        startTimeFrom: $('#start-time')["0"].value,
        startTimeTo: $('#end-time')["0"].value,
        callDurationMin: $('.start-num')["0"].value,
        callDurationMax: $('.end-num')["0"].value,
        initiator: $('#formInit').val(),
        proid: proName_select,
        isEffective: isEffective_select,
        calledDuration: calledDuration_V,
        callStatus: callStatus_select.split('#')[0]=="null"?'':callStatus_select.split('#')[0],
        rejectStatus:callStatus_select.split('#')[1]=="null"?'':callStatus_select.split('#')[1],
        yzth: isGoodCall_select,
        pageNum: page_index + 1,
        orderBy: orderBy

    }
    return queryjson;
}

function getCount() {
    var result = 0;
    var qjson=getJson(0, 0);
    $.ajax(
        {
            type: "post",
            url: "/call/calllistcount",
            data: qjson,
            dataType: "json",
            async: false,
            success: function (data) {
                result = data.data;
            }, error: function () {
            alert("报错了");
        }
        }
    );
    return result;
}
// 录音播放弹窗
$('.audio-btn').on('click', function () {
    $("#audio-detail").cmsmodal('show');

})


function getFormatDateStr(obj){
    return  getFormatDate(obj );
    
}